<?php
	require_once('../libraryfiles/config.php');
	$content = 'viewprescription.php';
	$include = '
	<script src="'.W_ROOT.'/js/common.js" type="text/javascript"></script>
	';    
	require_once TMP_USER_PATH;
	$user_id = $_SESSION['acc_id'];
	$view = isset($_GET['view'])?$_GET['view']:'';
	echo '
	<div class="row-fluid">
	<div class="box">
	<form name="frmlist" action="#" method="post">';
	switch($view){
		// detail
		case'detail':
		$order_id = isset($_GET['orderId'])?$_GET['orderId']:'';
		$sql_d = "SELECT * FROM tblordernance WHERE ordernance_id = $order_id AND user_id = $user_id AND isDeleted = 0";
		$result_d = mysql_query($sql_d);
		if(dbNumRows($result_d)){
			$row_d = mysql_fetch_assoc($result_d);
			extract($row_d);
		?>
    	<div class="title">View Prescription</div>
        <p align="center" style="font-size:20px;">Prescription</p>
        <table cellpadding="5" cellspacing="5" border="0">
        <tbody>
        <tr>
        <td>Patient Name</td><td width="5">:</td><td width="200"><?php echo stripslashes($patient_name);?></td>
        <td align="left">Age</td><td width="5">:</td><td><?php echo $age;?></td>
        
        </tr>
        <tr>
        <td align="left">Sex</td><td width="5">:</td><td><?php echo $sex;?></td>
        <td>Weight</td><td width="5">:</td><td><?php echo $p_weight;?> kg</td>        
        </tr>
        <tr>
        <td align="left">Prescription Number<td width="5">:</td><td><?php echo $ordernance_code;?></td> 
        <td>Height</td><td width="5">:</td><td><?php echo $p_height;?> m</td>
        </tr>
        <tr>
        <td>Check Date</td><td width="5">:</td><td><?php echo $check_date;?></td>       
        <td>Doctor Name</td><td width="5">:</td><td><?php echo $doctor_name;?></td>
        </tr>
        <tr>
        <td valign="top">Note</td>
        <td width="5" valign="top">:</td>
        <td colspan="7">
        <?php echo stripslashes($note);?>
        </td>
        </tr>
        </tbody>
        </table>
        <br />
        <table cellpadding="0" cellspacing="0" border="0" id="displayPro" width="100%" style="padding:0px 2px 0px 2px;">
        <tbody>
            <tr id="displayTR">
            <td width="30" class="col3" align="center">N&deg;</td>
            <td width="100" align="center" class="col3">Image</td>
            <td align="center" width="250" class="col3">Product Name</td>
            <td align="center" width="150" class="col3_1">Quantity</td>
            </tr>
            <?php
			$i=1;
			$sql = "SELECT * FROM tblproduct_in_ordernance WHERE order_id = $order_id";
			$result = mysql_query($sql);
			while($row = mysql_fetch_assoc($result)){
			$sql_img = "SELECT thumbnail FROM tblimage WHERE product_id = ".$row['product_id']." LIMIT 0,1";
				$result_img = mysql_query($sql_img);
				$row_img = mysql_fetch_assoc($result_img);
			if($row_img['thumbnail']!=""){
					$thumbnail_i = 	$row_img['thumbnail'];
				}else{
					$thumbnail_i = 	'no-image-small.png';
				}
			?>
            <tr>
            <td width="30" class="col4" align="center"><?php echo idFormat($i);?></td>
            <td width="100" align="center" class="col4"><img src="<?php echo W_S_IMAGES_DIR.$thumbnail_i; ?>" class="border" width="50" /></td>
            <td align="center" width="250" class="col4"><strong style="color:#06C;"><?php echo getProductName($row['product_id'])?></strong><br />
            <em style="color:#666;">Made in : <?php echo getCountryName($row['made_in']);?></em>
            </td>
            <td align="center" width="150" class="col4_1">
            <?php
			echo $row['quatity'];
			?>
            </td>
	        </tr>
            <?php
			}
			?>
            <tr>
            <td colspan="4" style="padding:10px 2px 10px 0px;" align="right">
            <input class="btn" type="button" name="btnback" value="Back" onclick="window.location.href='viewprescription.php'" />
            </td>
            </tr>
        </tbody>
        </table>
        <?php
		}
		break;
		
		// list
		default:
		$sql_l = "SELECT ordernance_id, user_id, ordernance_code, cdate FROM tblordernance WHERE user_id = $user_id AND isDeleted = 0";
		$result_l = mysql_query($sql_l);
		?>
        <p align="right" style="padding-right:2px;">
        <input class="btn" type="button" name="btnunpublish" value="Delete" onclick="deleteSelected(document.frmlist,'<?php echo htmlspecialchars(getAllGetParams(array('action','view')));?>','Prescription(s)','process');" />
        </p>
        <table cellpadding="0" cellspacing="0" border="0" id="displayPro" width="100%" style="padding:10px 2px 0px 2px;">
        <tbody>
            <tr>
            <td width="50" class="col3" align="center">N&deg;</td>
            <td width="20" class="col3" align="center"><input type="checkbox" name="chkall" id="chkall" onClick="checkAll(this.form,this.checked)" style="cursor:pointer;"></td>
            <td width="180" align="center" class="col3">Prescription Number</td>
            <td align="center" width="200" class="col3">Post Date</td>
            <td align="center" width="100" class="col3_1">View</td>
            </tr>
            <?php
			$i = 1;
			if(dbNumRows($result_l)){
			while($row_l = mysql_fetch_assoc($result_l)){
				extract($row_l);
			?>
            <tr>
            <td class="col4" align="center"><?php echo idFormat($i);?></td>
            <td class="col4" align="center"><input type="checkbox" name="id[]" value="<?php echo $ordernance_id;?>"/>
            </td>
            <td class="col4" align="center"><?php echo $ordernance_code;?></td>
            <td class="col4" align="center"><?php echo $cdate?></td>
            <td class="col4_1" align="center"><a href="<?php $_SERVER['PHP_SELF']?>?view=detail&orderId=<?php echo $ordernance_id?>" style="color:#03F;">View</a></td>
            </tr>
            <?php
			$i++;
			}
			}// end if
			else{
			?>
            <tr>
            <td colspan="4"><h3 align="center">No Prescription yet!</h3></td>
            </tr>
            <?php	
			}
			?>
        <tbody>
        </table>
        <br />
        <?php
		break;
	}
?>
	</div><!--<div class="box">-->
</div><!--<div class="row-fluid">-->
</form>
